#ifndef _REACTOR_IMPL_H
#define _REACTOR_IMPL_H


namespace NetIO
{

class DllExport Reactor_Impl
{
public:
	Reactor_Impl( void );

public:
	virtual ~Reactor_Impl( void );

	int async_read( Socket handle, DataBlock *data_block, void *act );

	int async_write( Socket handle, DataBlock *data_block, void *act );

	int async_connect( const string &ip, short port, void *act );

	int async_accept( Socket listen_handle, void *act );

	int run( );

	void close( );

	int operation_result( Operation_Result &result );

	int register_handler( Socket &handle );

	void close_handle( Socket &handle );

public:
	virtual void cancel_handle( Socket handle ) = 0;
	virtual int run_once( ) = 0;

private:
	virtual int register_handler_i( Socket &handle ) = 0;

	virtual int start_op( Socket &handle, Operation *op ) = 0;

	void cancel_all_op( );

protected:

	int handle_all_complete_op( );

protected:

	typedef hash_map< EventHandle, Handle_Data* > handle_map;

	Reactor_Interrupter interrupter_;
	handle_map			handle_map_;
	Synch_Mutex			handle_map_mutex_;
	Synch_Mutex			mutex_;
	Operation_Queue		complete_operations_;
	int exit_;
	Completed_Queue		result_queue_;
private:
#ifndef WIN32
	static SignalIgnore<> signal_pipe_;
#endif

};

};

#endif
